﻿<Result Icon="@icon"
        Status="@status"
        Title="@title"
        SubTitle="@subTitle">
</Result>
<Divider/>
<Space Direction="SpaceDirection.Vertical" Size="SpaceSize.Large">
    <SpaceItem>
        <Space>
            <SpaceItem>
                <Text>Select Icon</Text>
            </SpaceItem>
            <SpaceItem>
                <RadioGroup TValue="string" @bind-Value="icon" Size="InputSize.Large" OnChange="Rb_OnChange">
                    <Radio RadioButton Value="@("smile-outline")">
                        <Icon Type="@IconType.Outline.Smile" />
                    </Radio>
                    <Radio RadioButton Value="@("like-outline")">
                        <Icon Type="@IconType.Outline.Like" />
                    </Radio>
                    <Radio RadioButton Value="@("bug-outline")">
                        <Icon Type="@IconType.Outline.Bug" />
                    </Radio>
                    <Radio RadioButton Value="@("")">
                        Use Image
                    </Radio>
                </RadioGroup>
            </SpaceItem>
        </Space>
    </SpaceItem>
    <SpaceItem>
        <Space>
            <SpaceItem>
                <Text>Select Result</Text>
            </SpaceItem>
            <SpaceItem>
                <Select TItem="ResultStatus" TItemValue="ResultStatus" Style="width: 150px;" @bind-Value="@status" OnSelectedItemChanged="Cbo_OnSelectedItemChanged">
                    <SelectOptions>
                        <SelectOption Label="Icon-Info" Value="ResultStatus.Info" />
                        <SelectOption Label="Icon-Warning" Value="ResultStatus.Warning" />
                        <SelectOption Label="Icon-Error" Value="ResultStatus.Error" />
                        <SelectOption Label="Icon-Success" Value="ResultStatus.Success" />
                        <SelectOption Label="Image-403" Value="ResultStatus.Http403" />
                        <SelectOption Label="Image-404" Value="ResultStatus.Http404" />
                        <SelectOption Label="Image-500" Value="ResultStatus.Http500" />
                    </SelectOptions>
                </Select>
            </SpaceItem>
        </Space>
    </SpaceItem>
</Space>

@code
{
    private ResultStatus status = ResultStatus.Info;
    private string icon = "smile-outline";
    private string title = "smile-outline";
    private string subTitle = "The status is info, and the icon used is 'smile-outline'";

    private void Rb_OnChange(string value)
    {
        bool isImageStatus = status.IsIn(ResultStatus.Http403, ResultStatus.Http404, ResultStatus.Http500);
        bool isUseIcon = !string.IsNullOrEmpty(value);
        if (!isUseIcon)
        {
            if (!isImageStatus)
            {
                status = ResultStatus.Http403;
            }
        }
        else if (isImageStatus)
        {
            status = ResultStatus.Info;
        }

        title = isUseIcon ? icon : status.ToString();
        subTitle = $"The status is {status}";
        if (isUseIcon)
        {
            subTitle += $" and the icon used is '{icon}'";
        }
    }

    private void Cbo_OnSelectedItemChanged(ResultStatus value)
    {
        if (value.IsIn(ResultStatus.Http403, ResultStatus.Http404, ResultStatus.Http500))
        {
            icon = "";
        }

        bool isUseIcon = !string.IsNullOrEmpty(icon);
        title = isUseIcon ? icon : status.ToString();
        subTitle = $"The status is {status}";
        if (isUseIcon)
        {
            subTitle += $" and the icon used is '{icon}'";
        }
    }
}
